package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminDishController")
@RequestMapping("/admin/dish")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;


    /**
     * 新增菜品
     * @param dto
     * @return
     */
    @PostMapping
    public Result addDish(@RequestBody DishDTO dto){
        return dishService.addDish(dto);
    }


    /**\
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Result pageQuery(DishPageQueryDTO dto){
        return dishService.pageQuery(dto);
    }


    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        return dishService.getById(id);

    }


    /**
     *修改菜品
     * @param dto
     * @return
     */
    @PutMapping
    public Result updateDish(@RequestBody DishDTO dto){
        return dishService.updateDish(dto);
    }




    /**
     * 菜品禁用启用修改
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id ){
        return dishService.updateStatus(status, id);
    }

    /**
     * 菜品删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids) {
        log.info("菜品批量删除：{}", ids);
        return dishService.deleteBatch(ids);
    }


    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    public Result SelectByCategoryId( Long categoryId){
        return dishService.SelectByCategoryId(categoryId);

    }


}
